﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;
using Lilium.Web.Mvc.AjaxControlToolkit;

namespace Lilium.Web.Mvc.Configuration
{
	/// <summary>
	/// Конфигурационный элемент для встроенного AjaxControlToolkit-скрипта.
	/// </summary>
	public class EmbeededToolkitScriptElement: EmbeededResourceElement
	{
		#region public ClientScriptResourceElementCollection ClientResources

		private const string ClientResourcesPropertyName = "clientResources";

		[ConfigurationPropertyAttribute(ClientResourcesPropertyName)]
		public ToolkitScriptResourceElementCollection ClientResources
		{
			[DebuggerNonUserCodeAttribute]
			get
			{
				var collection = (ToolkitScriptResourceElementCollection)base[ClientResourcesPropertyName];
				if (collection != null)
					collection.ToolkitScript = this;
				return collection;
			}
		}

		#endregion

		public override ScriptResource GetScriptResource()
		{
			return new EmbeededToolkitScriptResource(
				Name,
				GetResourceAssembly(),
				GetResourceName(),
				GetContentType(),
				GetOutputCachePolicy(),
				ClientResources.Select(a => a.GetClientScriptResource()));
		}
	}
}